//快递默认图片
export const errorExpressImg = 'https://oss.qmxip.com/flash_goods/1088155186259398656.png'

import { $getImg } from './index'

export const  statusList =  [

    { num: 5, name: "待支付" },{ num: 8, name: "待配送", subName: "已支付" }, { num: 10, name: "待配送" }, 
    { num: 30, name: "已取消",subName: "用户取消"},   { num: 40,name: "已取消", subName: "商家取消" }, { num: 50, name: "退款中" },{ num: 60, name: "已退款" },
    { num: 10000, name: "待配送" }, { num: 20000, subName: "商家取消" ,name:'已取消'},{ num: 20001, subName: "配送方取消",name:'已取消' },
    { num: 30000, subName: "配送员接单" ,name:'配送员已接单'}, { num: 40000, subName: "配送员到店" ,name:'配送员已到店'},{ num: 50000, name: "配送中" },
    { num: 60000, subName: "配送员撤单",name:'配送员撤单' }, { num: 70000, name: "配送完成" },{ num: 90000, name: "配送异常" }

]


export const  goodsGroupPurchaseStatus =  [

    { num: 1, name: "拼团中" },{ num: 2, name: "拼团成功" }, { num: 3, name: "拼团失败" }

]


export function DealOrderInfo (data) {

        return data.map(item => {

            let orderStatusStr = ''

            //状态中文
            statusList.map(statusTtem => {

                if (statusTtem.num <= item.orderStatus) {

                    orderStatusStr = statusTtem.name
                }

            })

            item.orderStatusStr = orderStatusStr

            //商品图片

            if( item.orderGoodsModelList && item.orderGoodsModelList.length >0){
                item.orderGoodsModelList.map(pItem => {

                    pItem.listPictureSrc = pItem.goodsPic ? $getImg(pItem.goodsPic) : ''
    
                })

            }

            

            //快递图片
            if(item.orderExpressModelList && item.orderExpressModelList.length > 0){

                item.orderExpressModelList.map(pItem => {
                    // pItem.expressPic = pItem.goodsPic ? $getImg(pItem.goodsPic) : undefined
                    pItem.pics = pItem.expressPic ? pItem.expressPic.split(';'):[]
    
                })

            }
            //如果是拼团 1 正在拼 2 成功 3 失败
            if( item.ifGroupPurchase == 1 && item.orderStatus < 10000){

                // item.goodsGroupPurchaseStatusStr =  item.goodsGroupPurchaseStatus == 1 ? '拼团中' : item.goodsGroupPurchaseStatus == 2 ? '拼团成功' : '拼团失败'
                
                let itemJson = goodsGroupPurchaseStatus.find(pItem => pItem.num == item.goodsGroupPurchaseStatus)

                item.goodsGroupPurchaseStatusStr = itemJson?.name || '拼团中'

            }

            item.isHasSend = startSend( item )

            item.isHasCancel = candelOrder( item ) 

            item.isSHowDeliveryInfo =  deliveryInfoFunc( item ) 


            return item

        })

    }

    //开始配送
   function startSend (json) {

        if (json.orderStatus >= 8 && json.orderStatus <= 10) {

            return true
        }

        return false
    }
    //取消订单
    function candelOrder (json) {


        if (json.orderStatusStr.includes('已取消') ) {

            return true
        }

        return false

    }
    //是否显示配送信息
    function  deliveryInfoFunc (json) {

        if ( json.orderStatus >=10000 &&  !json.isHasCancel) {

            return true
        }

        return false

    }